package lec05.am;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class Calculator extends Frame implements ActionListener, WindowListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	TextField ta, tb, tc;
	Button eq;

	public Calculator() {
		this.setLayout(new FlowLayout());
		this.add(ta = new TextField(10));
		this.add(new Label("+"));
		this.add(tb = new TextField(10));
		this.add(eq = new Button("="));
		this.add(tc = new TextField(10));
		this.setSize(400, 100);
		eq.addActionListener(this);
		this.addWindowListener(this);
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new Calculator();
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosing(WindowEvent e) {
		System.exit(0);

	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == eq) {
			// JOptionPane.showMessageDialog(null, "");
			int a = Integer.parseInt(ta.getText());
			int b = Integer.parseInt(tb.getText());
			tc.setText(Integer.toString(a + b));

		}

	}

}
